package com.ruoyi.web.controller.aggregation;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.aggregation.dto.PageDTO;
import com.ruoyi.system.domain.aggregation.MerchantAudit;
import com.ruoyi.system.service.aggregation.IMerchantAuditService;

/**
 * 商家审核Controller
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/agg/merchantAudit")
public class MerchantAuditController
{
    @Autowired
    private IMerchantAuditService merchantAuditService;

    /**
     * 分页查询商家审核
     */
    @PostMapping("/page")
    public AjaxResult page(@RequestBody PageDTO pageDTO)
    {
        try
        {
            PageHelper.startPage(pageDTO.getPageIndex().intValue(), pageDTO.getPageSize().intValue());
            MerchantAudit query = new MerchantAudit();
            List<MerchantAudit> list = merchantAuditService.selectMerchantAuditList(query);
            PageInfo<MerchantAudit> pageInfo = new PageInfo<>(list);
            return AjaxResult.success(pageInfo);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 添加商家审核
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MerchantAudit merchantAudit)
    {
        try
        {
            merchantAuditService.insertMerchantAudit(merchantAudit);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 编辑商家审核
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MerchantAudit merchantAudit)
    {
        try
        {
            merchantAuditService.updateMerchantAudit(merchantAudit);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 审核商家
     */
    @PostMapping("/check")
    public AjaxResult check(@RequestParam Long id, @RequestParam Integer statue, 
                           @RequestParam(required = false) String reason)
    {
        try
        {
            merchantAuditService.checkMerchantAudit(id, statue, reason);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 查看商家审核详情
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo(@RequestParam Long id)
    {
        try
        {
            MerchantAudit audit = merchantAuditService.selectMerchantAuditById(id);
            return AjaxResult.success(audit);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }
}

